import 'dart:convert';
import 'dart:io';
import 'package:base_flutter/base_flutter.dart' as b;
import 'package:dio/dio.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cupertino_date_picker_fork/flutter_cupertino_date_picker_fork.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ls_work/a_elder/models/code_value_entity.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/a_elder/widget/elder_header_image_cell.dart';
import 'package:ls_work/a_yyt/models/upload_entity.dart';
import 'package:ls_work/common/common.dart';
import 'package:ls_work/config/permission_center_config.dart';
import 'package:ls_work/mvp/svp_progress.dart';
import 'package:ls_work/net/HttpUtil.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/util/app_navigator.dart';
import 'package:ls_work/util/event_bus.dart';
import 'package:ls_work/util/toast.dart';
import 'package:ls_work/widgets/click_item.dart';
import 'package:ls_work/widgets/input_text_page.dart';
import 'package:ls_work/widgets/load_image.dart';
import 'package:permission_handler/permission_handler.dart';

import '../../util/ext_utils.dart';



class ElderDetailPage extends StatefulWidget {
  final ElderInfo info;
  ElderDetailPage({Key? key, required this.info});
  @override
  _ElderDetailPageState createState() => _ElderDetailPageState();
}

class _ElderDetailPageState extends State<ElderDetailPage> {
  TextEditingController textFieldEditer = TextEditingController();

  String _oldName = '';

  String _mobile = '';
  String _age = '';
  String _oldSex = '';
  int _oldSexId = 0;
  String _birthday = '';

  String _health = '';
  int _healthId = 0;
  String _address = '';
  String _addressSring = '';
  int _addressId = 0;
  String _eduDegree = '';
  int _eduDegreeId = 0;
  String _faith = '';
  int _faithId = 0;
  String _specialDiseaseRemark = '';
  String _idCardNumber = '';

  // String _groupActivity = '';
  bool canOpenStaffPage = false;
  DateTime _selectedDate = DateTime.now(); //当前选中的日期
  int _certificateTypeId = 0;
  String _certificateTypeStr = '';
  String _healthExaminationYearTimes = '';
  String _hospitalizeTimes = '';
  String _careTypeStr = '';
  int _careType = 0;
  String _experience = '';
  String _tripToolStr = '';
  int _tripTool = 0;
  String _changeReason = '';
  String _roomPreference = '';
  String _checkInPlan = '';
  String _choosePeopleName = '';

  List<CodeValue> idCardTypeList = [];
  List<CodeValue> healthList = [];
  List<CodeValue> addressList = [];
  List<CodeValue> eduList = [];
  List<CodeValue> faithList = [];
  List<CodeValue> careTypeList = [];
  List<CodeValue> tripToolList = [];

  File? _image;
  int? _headimageId;

  @override
  void initState() {
    super.initState();
    _fectcodeType(140); //身份证类型
    _fectcodeType(10);
    _fectcodeType(17);
    _fectcodeType(4);
    _fectcodeType(22);
    _fectcodeType(138);
    _fectcodeType(139);
    autoWrite(widget.info);
  }

  void autoWrite(ElderInfo info) {
    if (info != null) {
      _headimageId = info.headimageId;
      _hospitalizeTimes =
          info.hospitalizeTimes != null ? info.hospitalizeTimes.toString() : '';
      if (info.careType != null) {
        _careType = info.careType!;
        _careTypeStr = info.careTypeName??"";
      }
      if (info.tripTool != null) {
        _tripTool = info.tripTool!;
        _tripToolStr = info.tripToolName??"";
      }
      _experience = info.experience ?? '';
      _changeReason = info.changeReason ?? '';
      _roomPreference = info.roomPreference ?? '';
      _checkInPlan = info.checkInPlan ?? "";
      _choosePeopleName = info.choosePeopleName ?? "";
      _healthExaminationYearTimes = info.healthExaminationYearTimes != null
          ? info.healthExaminationYearTimes.toString()
          : "";

      _oldName = info.name ?? '';
      _age = info.age != null ? info.age.toString() : '';
      _oldSex = info.sex == 0 ? '男' : '女';
      _oldSexId = info.sex??0;
      if (info.birthday != null) {
        _birthday = DateUtil.formatDateStr(info.birthday??"", format: 'yyyy-MM-dd');
      } else {
        _birthday = '';
      }
      _mobile = info.mobile ?? '';

      _health = info.healthName ?? '';
      _healthId = info.healthId??0;
      _addressSring = info.preLiveName ?? '';
      _addressId = info.preLiveId??0;
      _idCardNumber = info.cardNo ?? '';

      _address = info.address ?? '';
      _faithId = info.faithId??0;
      _faith = info.faithName ?? '';

      _certificateTypeId = info.certificateTypeId??0;
      _certificateTypeStr = info.certificateTypeName ?? "";

      _eduDegree = info.eduDegreeName ?? '';
      _eduDegreeId = info.eduDegreeId??0;
      textFieldEditer.text = info.specialDiseaseRemark ?? '';
    }
  }

  ///上传信息
  _sendInfomation() async {
    if (_oldName.isEmpty) {
      Toast.show('请输入老人姓名');
      return;
    }
    Map<String, dynamic> params = Map();
    //contactsId 核查后的联系人id
    //intentionId 意向记录id,修改时必传
    params["mobile"] = _mobile;
    params['name'] = _oldName;

    if (widget.info.id != null) {
      params['customerId'] = widget.info.id;
    }
    if (widget.info.intentionId != null) {
      params['intentionId'] = widget.info.intentionId;
    }
    if (_headimageId != null) params["headimageId"] = _headimageId;
    if (_age.isNotEmpty) params['age'] = _age;
    if (_oldSex.isNotEmpty) params['sex'] = _oldSexId;
    if (_birthday.isNotEmpty) {
      String birthday = '$_birthday' + ' 00:00:00';
      params['birthday'] = birthday;
    }
    if (_mobile.isNotEmpty) params['mobile'] = _mobile;
    if (_idCardNumber.isNotEmpty) params['cardNo'] = _idCardNumber;
    if (_health.isNotEmpty) params['healthId'] = _healthId;
    if (_address.isNotEmpty) params['address'] = _address;
    if (_addressSring.isNotEmpty) params['preLiveId'] = _addressId;
    if (_eduDegree.isNotEmpty) params['eduDegreeId'] = _eduDegreeId;
    if (_faith.isNotEmpty) params['faithId'] = _faithId;
    if (_specialDiseaseRemark.isNotEmpty)
      params['specialDiseaseRemark'] = _specialDiseaseRemark;
    if (_healthExaminationYearTimes.isNotEmpty)
      params['healthExaminationYearTimes'] =
          int.parse(_healthExaminationYearTimes);
    if (_hospitalizeTimes.isNotEmpty)
      params['hospitalizeTimes'] = int.parse(_hospitalizeTimes);
    if (_careTypeStr.isNotEmpty) params['careType'] = _careType;
    if (_experience.isNotEmpty) params['experience'] = _experience;
    if (_tripToolStr.isNotEmpty) {
      params['tripTool'] = _tripTool;
      params['needTripTool'] = 1;
    } else {
      params['needTripTool'] = 0;
    }
    if (_changeReason.isNotEmpty) params['changeReason'] = _changeReason;
    if (_roomPreference.isNotEmpty) params['roomPreference'] = _roomPreference;
    if (_checkInPlan.isNotEmpty) params['checkInPlan'] = _checkInPlan;
    if (_choosePeopleName.isNotEmpty)
      params['choosePeopleName'] = _choosePeopleName;
    if (_certificateTypeStr.isNotEmpty)
      params['certificateTypeId'] = _certificateTypeId;

    SVProgressHUD page = SVProgressHUD(context);
    page.showProgress();
    HttpUtil.instance
        .getDio() //HttpApi.saveClientInfo, data: requestParams(params)
        .post("${HttpApi.saveClientInfo}?${requestParams(params)}")
        .then((r) {
      page.closeProgress();
      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());
        if (map['code'] == '0') {
          Toast.show(map["msg"]);
          eventBus.emit(Constant.eventElderInfoSave);
          Navigator.pop(context);
        } else {
          Toast.show(map["msg"]);
        }
      } else {
        Toast.show(r.statusCode.toString());
      }
    }).catchError((e) {
      page.closeProgress();
      Toast.show(getErrorMessage(e));
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('客户信息'),
        elevation: 0.5,
        actions: <Widget>[
          TextButton(
            child: Text(
              "保存",
              style: TextStyle(fontSize: 16, color: Colours.app_main),
            ),
            onPressed: _sendInfomation,
          )
        ],
      ),
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              ElderHeaderImageCell(
                info: widget.info,
                headimageId: _headimageId??0,
              ),
              ClickItem(
                title: "*姓名",
                content: _oldName,
                onTap: () {
                  AppNavigator.push(
                      context,
                      InputTextPage(
                        title: '姓名',
                        content: _oldName,
                        hintText: '请输入姓名',
                        onPress: (result) {
                          setState(() {
                            _oldName = result;
                          });
                        },
                      ));
                },
              ),
              Container(
                width: ScreenUtil.getScreenW(context),
                height: 60,
                margin: EdgeInsets.only(left: 12),
                padding: EdgeInsets.only(right: 15),
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(
                  color: Colours.line,
                ))),
                child: InkWell(
                  onTap: _pickImageFromSource,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Text(
                          "长者照片",
                          style: TextStyles.textDark14,
                        ),
                      ),
                      _image != null
                          ? Image.file(
                              _image!,
                              width: 60,
                              height: 60,
                              fit: BoxFit.fill,
                            )
                          : (_headimageId != null
                              ? LoadImage(
                                  "${HttpApi.imageDownLoadUrl}$_headimageId",
                                  height: 60,
                                  width: 60,
                                  fit: BoxFit.fill,
                                )
                              : Container()),
                      Gaps.hGap10,
                      LoadAssetImage(
                        'ic_arrow_right',
                        width: 20,
                        height: 20,
                      ),
                    ],
                  ),
                ),
              ),
              ClickItem(
                  title: "年龄",
                  content: _age,
                  onTap: () {
                    AppNavigator.push(
                        context,
                        InputTextPage(
                          title: '老人年龄',
                          content: _age,
                          hintText: '请输入老人年龄',
                          keyboardType: TextInputType.number,
                          onPress: (result) {
                            setState(() {
                              _age = result;
                            });
                          },
                        ));
                  }),
              ClickItem(
                title: "性别",
                content: _oldSex,
                onTap: _bottomOldManSexSheetAlert,
              ),
              ClickItem(
                title: "出生日期",
                content: _birthday,
                onTap: _showTimePicker,
              ),
              ClickItem(
                title: "联系电话",
                content: _mobile,
                onTap: () {
                  AppNavigator.push(
                      context,
                      InputTextPage(
                        title: '老人联系电话',
                        content: _mobile,
                        hintText: '请输入老人联系电话',
                        keyboardType: TextInputType.phone,
                        onPress: (result) {
                          setState(() {
                            _mobile = result;
                          });
                        },
                      ));
                },
              ),
              ClickItem(
                title: "身份证件归属",
                content: _certificateTypeStr,
                onTap: () {
                  _bottomFaithSheetAlert(
                    codeId: 140,
                    dataList: idCardTypeList,
                  );
                },
              ),
              ClickItem(
                title: "身份证号",
                content: _idCardNumber,
                onTap: () {
                  if (_certificateTypeStr.isEmpty) {
                    Toast.show('请先选择身份证归属');
                    return;
                  }
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '老人身份证号码',
                      content: _idCardNumber,
                      hintText: '请输入老人身份证号码',
                      keyboardType: TextInputType.emailAddress,
                      onPress: (result) {
                        setState(() {
                          _idCardNumber = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "身体状况",
                content: _health,
                onTap: _bottomHealthSheetAlert,
              ),
              ClickItem(
                title: "居住情况",
                content: _addressSring,
                onTap: _bottomAddressSheetAlert,
              ),
              ClickItem(
                title: "家庭住址",
                content: _address,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '家庭住址',
                      content: _address,
                      hintText: '请输入老人居住地址',
                      onPress: (result) {
                        setState(() {
                          _address = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "学历",
                content: _eduDegree,
                onTap: _bottomEduSheetAlert,
              ),
              ClickItem(
                title: "宗教信仰",
                content: _faith,
                onTap: () {
                  _bottomFaithSheetAlert(
                    codeId: 22,
                    dataList: faithList,
                  );
                },
              ),
              ClickItem(
                title: "每年体检次数",
                content: _healthExaminationYearTimes,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '每年体检次数',
                      content: _healthExaminationYearTimes,
                      hintText: '请输入老人每年体检次数',
                      keyboardType: TextInputType.number,
                      onPress: (result) {
                        setState(() {
                          _healthExaminationYearTimes = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "就医次数",
                content: _hospitalizeTimes,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '每年就医次数',
                      content: _hospitalizeTimes,
                      hintText: '请输入老人每年体检次数',
                      keyboardType: TextInputType.number,
                      onPress: (result) {
                        setState(() {
                          _hospitalizeTimes = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "照顾情况",
                content: _careTypeStr,
                onTap: () {
                  _bottomFaithSheetAlert(
                    codeId: 138,
                    dataList: careTypeList,
                  );
                },
              ),
              ClickItem(
                title: "入住养老院经历",
                content: _experience,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '入住养老院经历',
                      content: _experience,
                      hintText: '请输入入住养老院经历',
                      keyboardType: TextInputType.text,
                      onPress: (result) {
                        setState(() {
                          _experience = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "出行辅具",
                content: _tripToolStr,
                onTap: () {
                  _bottomFaithSheetAlert(
                    codeId: 139,
                    dataList: tripToolList,
                  );
                },
              ),
              ClickItem(
                title: "更换机构原因",
                content: _changeReason,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '更换机构原因',
                      content: _changeReason,
                      hintText: '请输入更换机构原因',
                      keyboardType: TextInputType.text,
                      onPress: (result) {
                        setState(() {
                          _changeReason = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "房间偏好",
                content: _roomPreference,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '房间偏好',
                      content: _roomPreference,
                      hintText: '请输入房间偏好',
                      keyboardType: TextInputType.text,
                      onPress: (result) {
                        setState(() {
                          _roomPreference = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "入住计划",
                content: _checkInPlan,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '入住计划',
                      content: _checkInPlan,
                      hintText: '请输入入住计划',
                      keyboardType: TextInputType.text,
                      onPress: (result) {
                        setState(() {
                          _checkInPlan = result;
                        });
                      },
                    ),
                  );
                },
              ),
              ClickItem(
                title: "抉择人姓名",
                content: _choosePeopleName,
                onTap: () {
                  AppNavigator.push(
                    context,
                    InputTextPage(
                      title: '抉择人姓名',
                      content: _choosePeopleName,
                      hintText: '请输入抉择人姓名',
                      keyboardType: TextInputType.text,
                      onPress: (result) {
                        setState(() {
                          _choosePeopleName = result;
                        });
                      },
                    ),
                  );
                },
              ),
              Padding(
                padding: EdgeInsets.all(15),
                child: Text(
                  '特殊病史',
                  style: TextStyles.textDark14,
                ),
              ),
              Container(
                padding: EdgeInsets.fromLTRB(15, 0, 15, 15),
                child: TextField(
                  controller: textFieldEditer,
                  maxLines: 5,
                  autofocus: false,
                  decoration: InputDecoration(
                    hintText: "请输入特殊病史",
                    hintMaxLines: 5,
                    fillColor: Colours.bg_color,
                    filled: true,
                    border: InputBorder.none,
                  ),
                ),
              ),
              // Padding(
              //   padding: EdgeInsets.all(12),
              //   child: Text(
              //     '家庭联系人',
              //     style: TextStyles.textBoldDark18,
              //   ),
              // ),
              // ClickItem(
              //   title: "姓名",
              //   content: '$_preName       $_sex',
              // ),
              // ClickItem(
              //   title: "联系电话",
              //   content: _preMobile,
              // ),
              // ClickItem(
              //   title: "关系",
              //   content: _relationshipName,
              // ),
            ],
          ),
        ),
      ),
    );
  }

  ///选择图片方式
  _pickImageFromSource() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return new Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            new ListTile(
              leading: new Icon(Icons.photo_camera),
              title: new Text("相机"),
              onTap: () async {
                Navigator.pop(context);

                Permission.camera.checkRequestPermission(
                  context,
                  onSuccess: () async {
                    var imageFile =
                    await ImagePicker().pickImage(source: ImageSource.camera);
                    if(imageFile!=null){
                      setState(() {
                        _image = File(imageFile.path);
                        // makeLogoString(_image.path);
                        _upLoadImage(File(imageFile.path));
                      });
                    }
                  },
                  msg: "使用扫一扫扫描长者码、访客码等二维码以及拍照上传工作照片、长者头像、健康档案时，需要申请您的相机权限",
                );


              },
            ),
            new ListTile(
              leading: new Icon(Icons.photo_library),
              title: new Text("相册"),
              onTap: () async {
                Navigator.pop(context);
                var isAndroid13 = await isAndroid13OrAbove();
                if(isAndroid13){
                  Permission.photos.checkRequestPermission(
                    context,
                    onSuccess: () async {
                      var imageFile =
                      await ImagePicker().pickImage(source: ImageSource.gallery);
                      if(imageFile!=null){
                        setState(() {
                          _image = File(imageFile.path);
                          // makeLogoString(_image.path);
                          _upLoadImage(File(imageFile.path));
                        });
                      }
                    },
                    msg: "从相册选取上传工作照片、长者头像、健康档案时，需要申请您的相册权限",
                  );
                }else{
                  Permission.storage.checkRequestPermission(
                    context,
                    onSuccess: () async {
                      var imageFile =
                      await ImagePicker().pickImage(source: ImageSource.gallery);
                      if(imageFile!=null){
                        setState(() {
                          _image = File(imageFile.path);
                          // makeLogoString(_image.path);
                          _upLoadImage(File(imageFile.path));
                        });
                      }
                    },
                    msg: "从相册选取上传工作照片、长者头像、健康档案时，需要申请您的相册权限",
                  );
                }

              },
            ),
          ],
        );
      },
    );
  }

  _upLoadImage(File image) async {
    String path = image.path;
    print(path);
    var name = path.substring(path.lastIndexOf("/") + 1, path.length);
    var suffix = name.substring(name.lastIndexOf(".") + 1, name.length);
    FormData formData = new FormData.fromMap({
      'fileType': suffix,
      'fileToUpload': await MultipartFile.fromFile(path, filename: name),
    });
    SVProgressHUD page = SVProgressHUD(context);
    page.showProgress();
    HttpUtil.instance.getDio().post(HttpApi.upload, data: formData).then((r) {
      print('响应状态码' + r.statusCode.toString());
      page.closeProgress();
      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());
        if (map["code"].toString() == "0") {
          if (map['data'] != null) {
            Upload model = Upload.fromJson(map['data']);
            setState(() {
              _headimageId = model.id;
              Toast.show("头像上传成功");
            });
          } else {
            Toast.show(map["msg"]);
          }
        }
      } else {
        Toast.show(r.statusCode.toString());
      }
    }).catchError((e) {
      page.closeProgress();
      Toast.show(getErrorMessage(e));
    });
  }

  ///获取code码数据
  _fectcodeType(int type) async {
    Map<String, dynamic> _map = {'codeTypeId': type};
    HttpUtil.instance
        .getDio()
        .post(HttpApi.mapType, data:_map,options: PostRequest.urlencodedHeader)
        .then((r) {
      print('响应状态码' + r.statusCode.toString());
      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());
        if (map["code"].toString() == "0") {
          // print(map);
          if (map['data'] != null) {
            CodeValueEntity model = CodeValueEntity.fromJson(map['data']);
            if ((model.rows??[]).length > 0) {
              setState(() {
                if (type == 10) {
                  healthList = model.rows??[];
                } else if (type == 17) {
                  addressList = model.rows??[];
                } else if (type == 4) {
                  eduList = model.rows??[];
                } else if (type == 22) {
                  faithList = model.rows??[];
                } else if (type == 138) {
                  careTypeList = model.rows??[];
                } else if (type == 139) {
                  tripToolList = model.rows??[];
                } else if (type == 140) {
                  idCardTypeList = model.rows??[];
                }
              });
            }
          } else {
            Toast.show(map["msg"]);
          }
        }
      } else {
        Toast.show(r.statusCode.toString());
      }
    }).catchError((e) {
      print(e.toString());
      Toast.show(getErrorMessage(e));
    });
  }

  ///性别弹窗
  _bottomOldManSexSheetAlert() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return Container(
          width: double.infinity,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(25),
              topRight: Radius.circular(25),
            ),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ListTile(
                title: Text('男'),
                onTap: () {
                  setState(() {
                    _oldSex = '男';
                    _oldSexId = 0;
                  });
                  Navigator.pop(context);
                },
              ),
              Container(
                width: double.infinity,
                height: 1,
                color: Colours.line,
              ),
              ListTile(
                title: Text('女'),
                onTap: () {
                  setState(() {
                    _oldSex = '女';
                    _oldSexId = 1;
                  });
                  Navigator.pop(context);
                },
              ),
            ],
          ),
        );
      },
    );
  }

  //调起时间选择器
  _showTimePicker() {
    DatePicker.showDatePicker(
      context,
      minDateTime: DateTime.parse("1900-01-01"),
      maxDateTime: DateTime.now(),
      initialDateTime: _selectedDate,
      // DateTime.parse(formatDate(_selectedDate, [yyyy, "-", mm, "-", "dd"])),
      dateFormat: "yyyy-MM-dd",
      locale: DateTimePickerLocale.zh_cn,
      pickerTheme: DateTimePickerTheme(
        showTitle: true,
        confirm: Text('确定'),
      ),
      pickerMode: DateTimePickerMode.date, // show TimePicker
      onConfirm: (dateTime, List<int> index) {
        setState(() {
          print(dateTime);
          if (dateTime == null) {
            return;
          }
          this._selectedDate = dateTime;
          _birthday = DateUtil.formatDate(dateTime, format: 'yyyy-MM-dd');
          print(_birthday);
        });
      },
    );
  }

  ///学历列表 / 照顾情况 / 出行辅具 / 身份证归属
  _bottomFaithSheetAlert({required int codeId,required List<CodeValue> dataList}) {
    showModalBottomSheet(
      context: context,
      isScrollControlled: false,
      builder: (BuildContext context) {
        return SingleChildScrollView(
          child: Container(
            width: double.infinity,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: dataList.map((f) {
                return ListTile(
                  title: Text(f.nameCn??""),
                  onTap: () {
                    setState(() {
                      if (codeId == 22) {
                        _faith = f.nameCn??"";
                        _faithId = f.id??0;
                      } else if (codeId == 138) {
                        _careTypeStr = f.nameCn??"";
                        _careType = f.id??0;
                      } else if (codeId == 139) {
                        _tripToolStr = f.nameCn??"";
                        _tripTool = f.id??0;
                      } else if (codeId == 140) {
                        _certificateTypeStr = f.nameCn??"";
                        _certificateTypeId = f.id??0;
                      }
                    });
                    Navigator.pop(context);
                  },
                );
              }).toList(),
            ),
          ),
        );
      },
    );
  }

  ///健康列表
  _bottomHealthSheetAlert() {
    showModalBottomSheet(
      context: context,
      isScrollControlled: false,
      builder: (BuildContext context) {
        return Container(
          width: double.infinity,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: healthList.map((f) {
              return ListTile(
                title: Text(f.nameCn??""),
                onTap: () {
                  setState(() {
                    _health = f.nameCn??"";
                    _healthId = f.id??0;
                  });
                  Navigator.pop(context);
                },
              );
            }).toList(),
          ),
        );
      },
    );
  }

  ///居住列表
  _bottomAddressSheetAlert() {
    showModalBottomSheet(
      context: context,
      isScrollControlled: false,
      builder: (BuildContext context) {
        return Container(
          width: double.infinity,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: addressList.map((f) {
              return ListTile(
                title: Text(f.nameCn??""),
                onTap: () {
                  setState(() {
                    _addressSring = f.nameCn??"";
                    _addressId = f.id??0;
                  });
                  Navigator.pop(context);
                },
              );
            }).toList(),
          ),
        );
      },
    );
  }

  ///学历列表
  _bottomEduSheetAlert() {
    showModalBottomSheet(
        context: context,
        isScrollControlled: false,
        builder: (BuildContext context) {
          return Container(
            width: double.infinity,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: eduList.map((f) {
                return ListTile(
                  title: Text(f.nameCn??""),
                  onTap: () {
                    setState(() {
                      _eduDegree = f.nameCn??"";
                      _eduDegreeId = f.id??0;
                    });
                    Navigator.pop(context);
                  },
                );
              }).toList(),
            ),
          );
        });
  }
}
